﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TrainigWorkshop.Model;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace TrainigWorkshop.DAL
{
    public  class ClassRespository : IClassRespository
    {
        public SqlConnection conn;
        public ClassRespository(SqlConnection conn)
        {
            this.conn = conn;
        }
        public List<Grade> GetClassInfo()
        {
            List<Grade> result = new List<Grade>();
              try
                {
                    string SQL = "select ClassID,ClassName from dbo.Class";
                    conn.Open();
                    SqlCommand cmd = new SqlCommand();
                    cmd.Connection = conn;
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = SQL;
                    SqlDataAdapter da = new SqlDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    da.Fill(ds, "table");
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        Grade re = new Grade
                        {
                            ClassId = Convert.ToInt32(row[0]),
                            ClassName = row[1].ToString().Trim()

                        };
                        result.Add(re);

                    }
                  return result;
                }
            finally
            {
                conn.Close();
            }

        }
    }
}
